package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询电子围栏列表
 */
@HttpInlet(Conn.INLET_QUERY_FENCE)
public class GetQueryFence extends JTAsyGet<List<GetQueryFence.Fence>> {

    public String token = JTApplication.jtPreferences.readToken();

    public String is_open;

    public GetQueryFence(AsyCallBack<List<Fence>> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected List<Fence> parserBody(Object body) {

        List<Fence> list = new ArrayList<>();

        JSONArray array = ((JSONObject)body).optJSONArray("list");

        if(array != null){

            for (int i = 0 ; i < array.length() ; i ++){

                JSONObject o = array.optJSONObject(i);

                Fence fence = new Fence();

                fence.rangeNum = o.optDouble("rangeNum");

                fence.remark = o.optString("remark");

                fence.status = o.optString("status");

                fence.lng = o.optDouble("lng");

                fence.id = o.optString("id");

                fence.outOpen = o.optString("outOpen");

                fence.inOpen = o.optString("inOpen");

                fence.address = o.optString("address");

                fence.obdId = o.optString("obdId");

                fence.name = o.optString("name");

                fence.createTime = o.optString("createTime");

                fence.userId = o.optString("userId");

                fence.addressType = o.optString("addressType");

                fence.lat = o.optDouble("lat");

                fence.wgsLat = o.optDouble("wgsLat");

                fence.wgsLng = o.optDouble("wgsLng");

                fence.poiName = o.optString("poiName");

                fence.poiAddress = o.optString("poiAddress");

                fence.recommend_id = o.optString("recommend_id");

                fence.dataFrom = o.optString("dataFrom");

                fence.outStat = o.optString("outStat");

                fence.inStat = o.optString("inStat");

                list.add(fence);

            }

        }

        return list;

    }

    public static class Fence implements Serializable{

        public double rangeNum;

        public String remark;

        public String status;

        public double lng;

        public String id;

        public String outOpen;

        public String inOpen;

        public String address;

        public String obdId;

        public String name;

        public String createTime;

        public String userId;

        public String addressType;

        public double lat;

        public double wgsLat;

        public double wgsLng;

        public String poiName;

        public String poiAddress;

        public String recommend_id;

        public String dataFrom;

        public String outStat;

        public String inStat;

    }

}
